<?php
namespace app\common\enum;

class Questionnaire
{
    const QUESTION_TYPE_NUM = 6; //题型数:6
    const SINGLE            = "单选题";
    const MULTIPLE          = "多选题";
    const BLANK_LIST        = "文本填空题";
    const SINGLE_BLANK      = "单项填空题";
    const RECT_SINGLE       = "矩阵单选题";

    const MARK_SINGLE = "打分单选";
    const JUMP_SINGLE = "跳题单选";
    const RECT_BLANK  = "矩阵填空题";
    //const LOGIC_SINGLE = "单选逻辑";
    const NOTE       = "问卷分为：自动问卷和回复问卷,自动问卷只能有打分单选,回复问卷不能有打分单选";
    const BLANK_MARK = "$"; //切勿随便改变，改变前要先刷库，把以往的数据改变
                            //参数验证类型：int bool string string_list checkFormat

    //获取题型名称
    public static function getQuestionTypeName()
    {
        return [self::SINGLE, self::MULTIPLE, self::BLANK_LIST, self::SINGLE_BLANK, self::RECT_SINGLE, self::MARK_SINGLE, self::JUMP_SINGLE, self::RECT_BLANK/*,self::LOGIC_SINGLE*/];
    }

    //获取题型
    public static function getQuestionType()
    {
        return [
            0 => [
                'type'         => 'int',
                'option_num'   => 'int',
                'option'       => 'string_list',
                'necessary'    => 'bool',
                'title'        => 'string' /*, 'is_child' => 'bool'*/,
                'other_option' => 'int',
                'note'         => 'string'],
            1 => [
                'type'         => 'int',
                'option_num'   => 'int',
                'option'       => 'string_list',
                'min_choice'   => 'int',
                'max_choice'   => 'int',
                'necessary'    => 'bool',
                'title'        => 'string' /*, 'is_child' => 'bool'*/,
                'other_option' => 'int',
                'note'         => 'string'],

            2 => [
                'type'       => 'int',
                'blank_num'  => 'int',
                'text_list'  => 'string_list',
                'blank_rule' => 'array',
                'necessary'  => 'bool',
                'title'      => 'string' /*, 'is_child' => 'bool'*/,
                'note'       => 'string'],
            3 => [
                'type'      => 'int',
                'necessary' => 'bool',
                'title'     => 'string' /*, 'is_child' => 'bool'*/,
                'note'      => 'string'],
            4 => [
                'type'       => 'int',
                'option_num' => 'int',
                'option'     => 'string_list',
                'title_num'  => 'int',
                'title_list' => 'string_list',
                'necessary'  => 'bool',
                'title'      => 'string' /*, 'is_child' => 'bool'*/,
                'note'       => 'string'],

            5 => [
                'type'       => 'int',
                'option_num' => 'int',
                'option'     => 'string_list',
                'score'      => 'int_list',
                'title'      => 'string' /*, 'is_child' => 'bool'*/,
                'note'       => 'string'],
            6 => [
                'type'       => 'int',
                'option_num' => 'int',
                'option'     => 'string_list',
                'jump'       => 'int_list',
                'necessary'  => 'bool',
                'title'      => 'string',
                'note'       => 'string',
            ],

            7 => [
                'type'       => 'int',
                'option_num' => 'int',
                'option'     => 'string_list',
                'title_list'  => 'string_list',
                'necessary'  => 'bool',
                'title'      => 'string',
                'note'       => 'string',
            ],
//            7 => [
            //                'type' => 'int', 'option_num' => 'int', 'option' => [[
            //                    'choice_name' => 'string', 'score' => 'int', 'child' => ['id_list']]], 'is_child' => 'bool', 'title' => 'string',
            //                'note'=>'string']
        ];
    }

    //文本填空属性规则
    public static function checkBlankRule($rule)
    {
        /* [
            'type'=>'int',
            'min'=>'int',
            'max'=>'int'
        ];*/
        /* type:["数字","文本","电话"]
         * */
        foreach ($rule as $item) {
            if (! key_exists('type', $item)) {
                return false;
            }
            switch ($item['type']) {
                case 0:
                    if (! key_exists('min', $item) || ! checkValueType($item['min'], 'int')) {
                        return false;
                    }
                    if (! key_exists('max', $item) || ! checkValueType($item['max'], 'int')) {
                        return false;
                    }
                    if ($item['min'] > $item['max']) {
                        return false;
                    }
                    //判断有没有无关项
                    if (count($item) != 3) {
                        return false;
                    }
                    break;
                case 1:
                    if (! key_exists('min', $item) || ! checkValueType($item['min'], 'int')) {
                        return false;
                    }
                    if (! key_exists('max', $item) || ! checkValueType($item['max'], 'int')) {
                        return false;
                    }
                    if ($item['min'] > $item['max'] || $item['min'] < 1) {
                        return false;
                    }
                    //判断有没有无关项
                    if (count($item) != 3) {
                        return false;
                    }
                    break;
                case 2:
                    //判断有没有无关项
                    if (count($item) != 1) {
                        return false;
                    }
                    break;
                default:
                    return false;
            }

        }
        return true;

    }

    //获取定义问卷所需参数
    public static function getParamAddQFormatNeed()
    {
        return [
            "q_class_id"   => 'int',
            "format"       => 'array',
            "available"    => 'bool',
            "show_mode"    => 'int',
            "full_mark"    => 'int',
            "pass_mark"    => 'int',
            "is_automatic" => 'bool',
            'name'         => 'string',
            'header_note'  => 'string',
        ];
    }

    //获取分数显示模式
    public static function getMarkShowMode()
    {
        return [
            "只显示及格与否",
            "完全显示分数",
            "不及格隐藏分数",
        ];
    }

    //获取填写问卷参数要求
    public static function getDoneQuestionnaireParamRule()
    {
        return [
            "qid"  => "int",
            "data" => "array",
        ];
    }

    //获取填写问卷参数要求
    public static function getDoneQuestionnaireDataRule()
    {
        return [
            ["id" => "int", "type" => "int" /*0*/, "choice" => "int", "other_str" => "string"],           //0单选
            ["id" => "int", "type" => "int" /*1*/, "choice_list" => "int_list", "other_str" => "string"], //1多选
            ["id" => "int", "type" => "int" /*2*/, "answer_list" => "string_list"],                       //2填空列表
            ["id" => "int", "type" => "int" /*3*/, "answer" => "string"],                                 //3单项填空
            ["id" => "int", "type" => "int" /*4*/, "answer_list" => "int_list"],                          //4矩阵单选
            ["id" => "int", "type" => "int" /*5*/, "choice" => "int"],                                    //5打分单选
            ["id" => "int", "type" => "int" /*6*/, "choice" => "int"],                                    //6跳题单选
            ["id" => "int", "type" => "int" /*6*/, "choice" => "int", "answer_list" => "string_list"],    //7矩阵填空
        ];
    }
}
